home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-11
/
pdrd2.zip
/
RD.ZIP
/
RD_DEMO8.PRG
< prev
next >
Wrap
Text File
|
1993-01-11
|
3KB
|
89 lines
/*
RD_DEMO8.PRG
Demonstration of key validation feature.
*/
#include "read.ch"
//---------
func main()
local getlist[0]
local dDate := date()
local cIdNum := "A000"
local nT := 4, nL := 10, nB := 7, nR := 26
local cColor := setcolor( if( iscolor(), "W+/BG, GR+/R,,, N/R", nil ) )
local aScn, aScn2
local bConfig := {|e| ADr_keyvalid( e,{|cKey,nPos,nthGet,cBuffer| Xkeyvalid(cKey,nPos,nthGet,cBuffer)} )}
cls
aScn = ADbox( nT, nL, nB, nR )
@nT+1, nL+2 say "Date" adget dDate
@nT+2, nL+2 say "ID #" adget cIdNum picture "!999"
aScn2 = ADmessage( { "Every key is validated. For example, you cannot enter a '3' in",;
"the Date's first position. Neither can you enter anything higher",;
"than '2' if the first is a '0'. As for ID #, you can only enter",;
"either an 'A' or a 'B' in the first position, and only digits in",;
"the other positions.";
}, 16,, .f., .f. )
ADread( getlist, bConfig )
ADrestscn( aScn2 )
ADrestscn( aScn )
setcolor( cColor )
return nil
//-------------------------------------------
func Xkeyvalid( cKey, nPos, nthGet, cBuffer )
local lValid := .t.
if nthGet = 1
if nPos = 1
if !cKey $ "01"
ADmessage( { "Only '0' and '1' are valid in the first position" } )
lValid = .f.
endif
elseif nPos = 2
if left( cBuffer, 1 ) == "0" .and. cKey == "0"
ADmessage( { "'0' is not valid in the second position" } )
lValid = .f.
elseif left( cBuffer, 1 ) == "1" .and. !cKey $ "012"
ADmessage( { "Only '0', '1' and '2' are valid in the second position" } )
lValid = .f.
endif
elseif nPos = 4
if !cKey $ "0123"
ADmessage( { "Only '0', '1', '2', and '3' are valid in the 4th position" } )
lValid = .f.
endif
elseif nPos = 5
if substr( cBuffer, 4, 1 ) == "3" .and. !cKey $ "01"
ADmessage( { "'0' and '1' are valid in the 5th position" } )
lValid = .f.
endif
elseif nPos = 7
if cKey != "9"
ADmessage( { "Only '9' is valid in the 7th position" } )
lValid = .f.
endif
elseif nPos = 8
if !cKey $ "0123"
ADmessage( { "Only '0', '1', '2', and '3' are valid in the last position" } )
lValid = .f.
endif
endif
elseif nthGet = 2
if nPos = 1
if !cKey $ "ABab"
ADmessage( { "Only 'A' and 'B' are valid in the first position" } )
lValid = .f.
endif
else
if !cKey $ "0123456789"
ADmessage( { "Only digits are valid in the 2nd to the last positions" } )
lValid = .f.
endif
endif
endif
return lValid